package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import org.apache.ibatis.annotations.Param;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: heima-leadnews
 * @description: 自媒体文章控制器
 * @author: ryp
 * @create: 2023-04-27 11:21
 **/
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 功能描述: 查询自媒体文章
     *
     * @param dto
     * @return : com.heima.model.common.dtos.PageResponseResult
     */
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto) {
        ResponseResult result = wmNewsService.findAll(dto);
        return result;
    }

    /**
     * 功能描述: 文章发布-存入草稿&提交审核
     * @param dto
     * @param draft
     * @return : com.heima.model.common.dtos.ResponseResult
     */
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto, @Param("draft") Boolean draft) throws Exception {
        ResponseResult result = wmNewsService.submitNews(dto, draft);
        return result;
    }

    /**
     * 功能描述: 自媒体文章上下架
     * @param dto
     * @return : com.heima.model.common.dtos.ResponseResult
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        return wmNewsService.downOrUp(dto);
    }
}
